# 744 简单：寻找比目标字母大的最小字母

# def nextGreatestLetter(self, letters: List[str], target: str) -> str:
def nextGreatestLetter(letters: [], target: str) -> str:
    l, r = 0, len(letters) - 1

    while l <= r:
        mid = (l + r) // 2
        if letters[mid] < target:
            l = mid + 1
        elif letters[mid] > target:
            r = mid - 1
        else:
            l += 1
            break

    print(l, r)
    return letters[l % len(letters)]


print(nextGreatestLetter(["a", "c", "f", "j", "x"], 'k'))
